Author: Nicolas Legrand nicolas.legrand@cfin.au.dk
import os
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import plotly.graph_objects as go
import plotly.express as px
from plotly.subplots import make_subplots
from systole.detection import oxi_peaks
from systole.plotly import plot_subspaces, plot_raw
import plotly.io as pio
pio.renderers.default='notebook'
sns.set_context('talk')
Import data
path = 'C:/Users/au646069/ECG/1_VPN_aux/'
subject = 'sub_0019'
# Parameters
subject = "sub_0023"
path = "C:/Users/au646069/ECG/1_VPN_aux/"
resultsFiles = os.listdir(os.path.join(path, subject, 'HBC'))
# Logs dataframe
df = pd.read_csv(os.path.join(path, subject, 'HBC', [file for file in resultsFiles if file.endswith('final.txt')][0]))
df
| nTrial | Reported | Condition | Duration | Confidence | ConfidenceRT | |
|---|---|---|---|---|---|---|
| 0 | 0 | 48 | Count | 40 | 6 | 12.822 |
| 1 | 1 | 43 | Count | 35 | 4 | 3.104 |
| 2 | 2 | 34 | Count | 30 | 3 | 6.883 |
| 3 | 3 | 55 | Count | 45 | 6 | 4.090 |
| 4 | 4 | 24 | Count | 25 | 5 | 2.602 |
| 5 | 5 | 51 | Count | 50 | 2 | 5.392 |
# PPG signal
ppg = {}
for i in range(6):
ppg[str(i)] = np.load(os.path.join(path, subject, 'HBC', f'{subject[4:]}_{i}.npy'))
signal, peaks = oxi_peaks(ppg['0'][0])
rr = np.diff(np.where(peaks)[0])
plot_subspaces(rr=rr, height=500)
plot_raw(signal, sfreq=1000)
print(f'Reported: {df.Reported.loc[0]} ; Detected : {np.sum(peaks)}')
Reported: 48 ; Detected : 66
signal, peaks = oxi_peaks(ppg['1'][0])
rr = np.diff(np.where(peaks)[0])
plot_subspaces(rr=rr, height=500)
plot_raw(signal, sfreq=1000)
print(f'Reported: {df.Reported.loc[1]} ; Detected : {np.sum(peaks)}')
Reported: 43 ; Detected : 58
signal, peaks = oxi_peaks(ppg['2'][0])
rr = np.diff(np.where(peaks)[0])
plot_subspaces(rr=rr, height=500)
plot_raw(signal, sfreq=1000)
print(f'Reported: {df.Reported.loc[2]} ; Detected : {np.sum(peaks)}')
Reported: 34 ; Detected : 49
signal, peaks = oxi_peaks(ppg['3'][0])
rr = np.diff(np.where(peaks)[0])
plot_subspaces(rr=rr, height=500)
plot_raw(signal, sfreq=1000)
print(f'Reported: {df.Reported.loc[3]} ; Detected : {np.sum(peaks)}')
Reported: 55 ; Detected : 72
signal, peaks = oxi_peaks(ppg['4'][0])
rr = np.diff(np.where(peaks)[0])
plot_subspaces(rr=rr, height=500)
plot_raw(signal, sfreq=1000)
print(f'Reported: {df.Reported.loc[4]} ; Detected : {np.sum(peaks)}')
Reported: 24 ; Detected : 44
signal, peaks = oxi_peaks(ppg['5'][0])
rr = np.diff(np.where(peaks)[0])
plot_subspaces(rr=rr, height=500)
plot_raw(signal, sfreq=1000)
print(f'Reported: {df.Reported.loc[5]} ; Detected : {np.sum(peaks)}')
Reported: 51 ; Detected : 78